﻿using DAL_13_0;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WyUnity.Data.TableMapper;

namespace SW_Interface.DTO
{
	[Serializable]
	public class BarcodeInfo
	{
		public string Number { get; set; }
		public string Name { get; set; }
		public decimal Qty { get; set; }
		public string UnitName { get; set; }
		public DateTime ProductDate { get; set; }
		public string Barcode { get; set; }
		public string ProductLine { get; set; }
		public string WorkClass { get; set; }


		public static BarcodeInfo Get(string barcode)
		{
			using (var db = DB.Open())
			{
				var b = new BarcodeInfo();
				b.Barcode = barcode;
				var ic = db.QuerySingle<v_ICItemInfo>(v_ICItemInfo.pBarcode == barcode.Substring(0, 5));
				b.Number = ic.Number;
				b.Name = ic.Name;
				b.Qty = ic.Coefficient;
				b.UnitName = ic.PackageUnitName;

				//product date
				b.ProductDate = Util.GetDateFromBarcode(barcode);

				//product line
				b.ProductLine = Util.GetProductLineFromBarcode(barcode);

				//work class
				b.WorkClass = Util.GetWorkClassFromBarcode(barcode);

				return b;
			}
		}
	}
}